DynamoDB Enhanced Client Polymorphic Types Support #6271
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
By default, the
DynamoDbEnhancedClientdoes not natively support storing multiple Java subclasses of a common supertype in the same table. In complex domain models (e.g. storing bothEmployeeandCustomerinstances ofPerson), there was a need to write complex type‐discrimination logic. This change introduces a clean, annotation‐driven layer that automatically dispatches to the correct subtype schema at runtime, reducing boilerplate and eliminating fragile manual checks.Modifications
@DynamoDbSubtypeDiscriminatorto mark the discriminator field on the base type.@DynamoDbSupertype(with innerSubtypeannotation) to declare each concrete subtype and its discriminator value on the supertype class.StaticAttributeTags.subtypeName()andSubtypeNameTagto record the discriminator attribute name inTableMetadata.StaticSubtype<T>encapsulates a subtype’sTableSchemaand its discriminator value.StaticPolymorphicTableSchema<T>implementsTableSchema<T>: reads the discriminator from the item or object, looks up the rightStaticSubtype, and delegates all mapping calls.PolymorphicTableSchema<T>wraps the static polymorphic schema for recursive resolution and caching.TableSchemaFactory.fromClass(...)to detect@DynamoDbSupertypeand route toPolymorphicTableSchema.create(...).EnhancedClientUtils.readAndTransformSingleItemand all core operations (Put, Update, Transact) to resolve and use the concrete subtype schema before invoking extensions or building requests.converterForAttribute(...)inStaticPolymorphicTableSchemato delegate to the root schema so user‐defined@DynamoDbConvertedByconverters continue to work seamlessly.Testing
StaticPolymorphicTableSchemacovering:mapToItem/itemToMap).Instant) are correctly applied viaconverterForAttribute.PersonandCustomersubclasses.beforeWrite/afterRead.Screenshots (if appropriate)
(See design doc diagrams in Section 4 and 5 for visual routing and flowchart illustrations.)
Test Coverage Checklist
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions.License